package com.viroyal.monitorlib.network.socket;

import java.io.UnsupportedEncodingException;

import io.netty.buffer.ByteBuf;

/**
 * 云端发过来的消息
 */
public class CloudMessage {
    public static final int TYPE_PING = 0;
    public static final int TYPE_DATA = 1;

    public int msgType;

    public String payload;

    public CloudMessage(ByteBuf buf) throws UnsupportedEncodingException {
        msgType = buf.readByte();
        if (buf.readableBytes() > 0) {
            byte[] bytes = new byte[buf.readableBytes()];
            buf.readBytes(bytes);
            payload = new String(bytes, "utf-8");
        }
    }

    @Override
    public String toString() {
        return "[type=" + msgType + " payload=" + payload + "]";
    }
}
